import json
import os


def merge(dirname, name):
    merge_data = {}
    for root, dirs, files in os.walk(dirname):
        for open_file in files:
            print(open_file)
            if open_file.endswith(".json"):
                file = open(os.path.join(root, open_file), 'r', encoding='UTF-8')
                merge_data[open_file[0:-5]] = json.load(file)
                file.close()
    save_file = open(name, 'w', encoding='UTF-8')
    json.dump(merge_data, save_file)
    save_file.close()


if __name__ == '__main__':
    merge("bin\\prefabs", 'bin\\res\\prefabs.json')
